package com.yao.smy.controller;

import com.yao.smy.domain.Equipment;
import com.yao.smy.dto.EquipmentDTO;
import com.yao.smy.service.EquipmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/equipments")
public class EquipmentController {

    @Autowired
    private EquipmentService equipmentService;

    @PostMapping
    public void addEquipment(@RequestBody Equipment equipment) {
        equipmentService.addEquipment(equipment);
    }

    @DeleteMapping("/{ip}")
    public void deleteEquipment(@PathVariable String ip) {
        equipmentService.deleteEquipment(ip);
    }

    @PutMapping
    public void updateEquipment(@RequestBody Equipment equipment) {
        equipmentService.updateEquipment(equipment);
    }

    @GetMapping("/{ip}")
    public EquipmentDTO getEquipment(@PathVariable String ip) {
        return equipmentService.getEquipment(ip);
    }

    @GetMapping
    public List<EquipmentDTO> getAllEquipments() {
        return equipmentService.getAllEquipments();
    }
}
